import type { WmsProductReturn, WmsProductReturnDetail } from "@/pages/wms/productReturn/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //退料单号
  returnCode?: string;
  //工单号
  workOrderCode?: string;
  //退料仓库
  warehouseId?: number;
  //单据状态
  status?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: WmsProductReturn[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/wms/product/return/pageList",
    data
});
const getInfo = (id: React.Key): Promise<WmsProductReturn> =>
  apiClient.get({
    url: `/wms/product/return/${id}`
});

const add = (data: WmsProductReturn): Promise<WmsProductReturn> =>
  apiClient.post({
    url: "/wms/product/return",
    data
});

const update = (data: WmsProductReturn): Promise<WmsProductReturn> =>
  apiClient.put({
    url: "/wms/product/return",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/wms/product/return",
    params: {
    ids: ids.join(",")
  }
});
const getDetails = (id: React.Key): Promise<WmsProductReturnDetail[]> =>
  apiClient.post({
    url: "/wms/product/return/detail/list",
    data: {
      returnId: id
    }
  });

export const wmsProductReturnService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
  getDetails,
};

export default wmsProductReturnService;